<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class UserRoles {
    var $id;
    var $app_user_id;
    var $app_role_id;

    function __construct($user_id,$role_id){
        global $db;
        $this->app_user_id=$user_id;
        $this->app_role_id=$role_id;
        $this->id=$this->insert();
    }
    function open($id){
        global $db;
        $sql="select * from user_roles where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->app_user_id=$app_user_id;
            $this->app_role_id=$app_role_id;

        }
    }

    function openAll(){
        $sql="select * from user_roles order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into user_roles values (null,'{$this->app_user_id}','{$this->app_role_id}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update user_roles set app_user_id='{$this->app_user_id}',
        app_role_id='{$this->app_role_id}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from user_roles where id=".$this->id;
        $db->query($sql);
    }

}
?>
